/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tuneControllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import tuneModels.Database;
import tuneViews.PlayerApp;
import tuneViews.Report;

/**
 *
 * @author Israel Agyeman-Prempeh
 */
public class ReportController {

    ActionListener actionListener;
    PlayerApp p;
    Database db;
    Report r;

    /**
     * A constructor that takes the specified parameters to generate a report.
     * In the UI it is labelled as the UI.
     *
     * @param r
     * @param db
     * @param p
     */
    public ReportController(Report r, Database db, PlayerApp p) {
        this.r = r;
        this.db = db;
        this.p = p;

    }

    /**
     * The control method of the report controller implements an action listener
     * to control the operation of the report (History)
     */
    public void control() {
        actionListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == p.report()) {
                    r.setVisible(true);
                    r.getList().setListData(db.getTableInfo().toArray());
                }
            }
        };

        /**
         * Action Events to check if themes have been selected
         */
        p.report().addActionListener(actionListener);

    }

}
